import { _decorator, Component, Node } from 'cc';
import { Actor } from './Actor';
import { VirtualInput } from '../input/VirtualInput';
import { StateDef } from '../config/StateDefine';
const { ccclass, property, requireComponent } = _decorator;

@ccclass('PlayerCtrl')
@requireComponent(Actor)
export class PlayerCtrl extends Component {
    private actor: Actor = null

    start() {
        this.actor = this.node.getComponent(Actor)
    }

    update(deltaTime: number) {
        this.actor.input.x = VirtualInput.horizontal
        this.actor.input.z = -VirtualInput.vertical

        if (this.actor.input.length() > 0) {
            this.actor.changeState(StateDef.Run)
        } else {
            this.actor.changeState(StateDef.Idle)
        }
    }
}


